assume cs:code, ds:data, ss:stack

data segment
    msg db "The 9mul9 table:",'$'
    multiply db 'x', '$'
    assign db '=', '$'
    crlf db 0ah, 0dh, '$'
    space db '  ', '$'
data ends

stack segment
    dw 0,0,0,0,0,0,0,0
stack ends


code segment
    start:
        mov ax, data
        mov ds, ax

        mov ax, stack
        mov ss, ax
        mov sp, 16

        ; 打印提示
        lea dx, msg
        mov ah, 09h
        int 21h

        lea dx, crlf
        mov ah, 09h
        int 21h

        mov cx, 9 ; 外层循环

    l1: push cx
        mov al, cl
    l2:     mov bl, cl ; 内层循环

            push ax
            add ax, 48
            mov dx,ax
            mov ah,02h
            int 21h

            lea dx, multiply
            mov ah, 09h
            int 21h

            push bx
            mov ax, bx
            add ax, 48
            mov dx, ax
            mov ah, 02h
            int 21h

            lea dx, assign
            mov ah, 09h
            int 21h

            ; 计算结果
            pop bx
            pop ax
            push ax
            mul bl

            ; 输出结果，判断是否两位数
            push bx
            mov bx, 10
            div bl
            cmp al, 0  ; 商是否为0

            JZ j1
            ; 输出商
            push ax
            add al, 48
            mov dx, 0
            mov dl, al
            mov ah, 02h
            int 21h

            pop ax

            ; 输出余数
         j1:   add ah, 48
            mov dx, 0
            mov dl, ah
            mov ah, 02h
            int 21h


            lea dx, space
            mov ah, 09h
            int 21h

            pop bx
            pop ax

            loop l2

        lea dx, crlf
        mov ah, 09h
        int 21h
        
        pop cx
        loop l1


        mov ax, 4c00h
        int 21h


code ends

end start
